<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('项目跟踪列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>项目号：</label>
                                <input type="text" name="projectNo"/>
                            </li>
                            <li>
                                <label>项目负责人：</label>
                                <input type="text" name="projectManager"/>
                            </li>
                            <li>
                                <label>产品型号：</label>
                                <input type="text" id="productModel" name="productModel" placeholder="请输入产品型号"/>
                            </li>
                            <li>
                                <label>预计到货时间：</label>
                                <input type="text" class="time-input" placeholder="请选择预计到货时间" name="expectedArrivalDate"/>
                            </li>
                            <li>
                                <label>实际到货时间：</label>
                                <input type="text" class="time-input" placeholder="请选择实际到货时间" name="actualArrivalDate"/>
                            </li>
                            <li>
                                <label>创建时间：</label>
                                <input type="text" class="time-input" placeholder="请选择创建时间" name="createdAt"/>
                            </li>
                            <li>
                                <label>更新时间：</label>
                                <input type="text" class="time-input" placeholder="请选择更新时间" name="updatedAt"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="ds:project:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="ds:project:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="ds:project:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="ds:project:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('ds:project:edit')}]];
        var removeFlag = [[${@permission.hasPermi('ds:project:remove')}]];
        var prefix = ctx + "ds/project";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "项目跟踪",
                pageSize: 100,
                striped: true,
                bordered: true,
                fixedColumns: true,
                fixedNumber: 2,
                pagination: true,
                clickToSelect: true,
                singleSelect: false,
                uniqueId: "id",
                showToggle: false,
                cardView: false,
                height: 650,
                stickyHeader: true,
                stickyHeaderOffsetY: 0,
                sortable: true,  // 启用排序功能
                sortName: "expectedArrivalDate",
                sortOrder: "desc", // 默认排序方式
                rowStyle: function(row, index) {
                    return {
                        classes: 'table-row'
                    };
                },
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '自增主键ID',
                    visible: false
                },
                {
                    field: 'projectNo',
                    title: '项目号',
                    formatter: function(value, row, index) {
                        return '<a href="javascript:void(0)" onclick="openTrack(\'' + value + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'projectManager',
                    title: '项目负责人',
                    sortable: true
                },
                {
                    field: 'paymentStatus',
                    title: '尾款情况',
                    sortable: true
                },
                {
                    field: 'expectedArrivalDate',
                    title: '预计到货时间',
                    sortable: true
                },
                {
                    field: 'actualArrivalDate',
                    title: '实际到货时间',
                    sortable: true
                },
                {
                    field: 'remarks',
                    title: '备注'
                },
                {
                    field: 'createdAt',
                    title: '创建时间'
                },
                {
                    field: 'updatedAt',
                    title: '更新时间'
                },
                {
                    field: 'isCompleted',
                    title: '是否完成',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return value ? '<span class="badge badge-success">是</span>' : '<span class="badge badge-danger">否</span>';
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
            
            // 添加自定义CSS样式
            $("<style>")
                .prop("type", "text/css")
                .html(`
                    .table-row td {
                        vertical-align: middle !important;
                        padding: 8px 5px !important;
                    }
                    .fixed-table-container thead th .th-inner {
                        padding: 8px 5px;
                    }
                    .btn-xs {
                        padding: 1px 5px;
                    }
                    .btn-group-sm>.btn, .btn-sm {
                        padding: 3px 8px;
                    }
                `)
                .appendTo("head");
        });

        // 打开供应商发货跟踪页面
        function openTrack(projectNo) {
            var url = ctx + "ds/track?projectNo=" + encodeURIComponent(projectNo) ;
            var productModel = $("#productModel").val();
            if(productModel != null && productModel != ""){
                url += "&productModel="+encodeURIComponent(productModel)
            }
            $.modal.openTab("供应商发货跟踪", url);
        }
    </script>
</body>
</html>